// pages/houseDetails/houseDetails.js
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    roomId:'',
      rent:{
        // houseId:1,
        // rentOrNot:true,
        // lesseePhone:18000000000
      },
      roomDetail: {},
      rentDetail: {}
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that=this;
    that.setData({
      roomId: options.room_id,
    })
    wx.showLoading({
      title: '加载中',
    })
    this.getDataHttps();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  },
  /**
  * https请求获取数据
  */
  getDataHttps: function () {
    var that=this;
    wx.request({
      url: app.globalData.url + '/wx/house/room/detail',
      header: {
        'token': wx.getStorageSync('token'),
        'content-type': 'application/x-www-form-urlencoded'
      },
      method: "POST",
      data: 'roomId=' + that.data.roomId,
      success: res => {
        console.log(JSON.stringify(res.data))
        if (res.data.code == 200) {
          if (res.data.data.roomDetail != null) {
            var furnitureList = new Array();
            if (res.data.roomDetail.hasOwnProperty('furniture')) {
              //如果对象中存在这个标签key，则解析封装
              var temp = res.data.roomDetail.furniture.split(',')
              for (var i in temp) {
                furnitureList.push(temp[i])
              }
            }
            //房屋标签
            res.data.data.roomDetail['furniture_list'] = furnitureList
          }
          //获取数据成功
          that.setData({
            roomDetail: res.data.roomDetail,
            rentDetail: res.data.rentDetail,
          })
        } else{
          wx.showModal({
            title: '提示',
            content: res.data.msg + '(' + res.data.code + ')',
            showCancel: false,
            success: res => { }
          })
        }
      },
      fail: res => {
        //请求接口失败
        var code = res.data.statusCode;
        var msg = res.data.errMsg;
        wx.showModal({
          title: '提示',
          content: msg + '(' + code + ')',
          showCancel: false,
          success: res => { }
        })
      },
      complete: res => {
        wx.hideLoading()
      }
    })
  }


})